package com.kongxx.struts2study.json;

import com.kongxx.struts2study.user.model.User;
import com.opensymphony.xwork2.Action;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.struts2.json.annotations.JSON;

public class JSONExample1 {

	private int[] ints = {10, 20};

	private List<User> userList = new ArrayList<User>();

	private Map<String, User> userMap = new HashMap<String, User>();

	private Date date = Calendar.getInstance().getTime();
	
	private String customName = "custom";

	private String field1 = "field1";

	//'transient' fields are not serialized
	private transient String field2 = "field2";
	
	//fields without getter method are not serialized
	private String field3;

	public String execute() {
		for (int i = 0; i < 2; i++) {
			User user = new User("id_" + i, "username_" + i, "password_" + i, "desc_" + i);
			userList.add(user);
			userMap.put(user.getId(), user);
		}
		return Action.SUCCESS;
	}

	public int[] getInts() {
		return ints;
	}

	public void setInts(int[] ints) {
		this.ints = ints;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public Map<String, User> getUserMap() {
		return userMap;
	}

	public void setUserMap(Map<String, User> userMap) {
		this.userMap = userMap;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	public String getField1() {
		return field1;
	}

	public void setField1(String field1) {
		this.field1 = field1;
	}

	public String getField2() {
		return field2;
	}

	public void setField2(String field2) {
		this.field2 = field2;
	}
	
	@JSON(name = "newCustomName")
	public String getCustomName() {
		return this.customName;
	}
}
